package com.lu.pojo.network.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author luzhenfang
 * @date 2020 05 16
 * @description tcp客户端
 */
public class TcpClient {
    private Socket socket = null;
    private OutputStream os =null;

    public static void main(String[] args) {
        TcpClient localhost = new TcpClient("127.0.0.1", 9999);
    }
    public TcpClient(String addr,int port){
        try {
            socket =new Socket(addr,port);
            os = socket.getOutputStream();
            os.write("你好,世界!".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
          if (os!=null){
              try {
                  os.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
            if (socket!=null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
